/**
 * @file STL_SYNTHESIZE.h
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 0.1
 * @date 2021-01-27
 * 
 * @copyright Copyright Sci-Tech Laboratories (c) 2021
 * 
 */

#include <functional>

// 对外可以获取和设置
#define STL_SYNTHESIZE(varType, varName, funName)                \
private:                                                         \
    varType varName;                                             \
                                                                 \
public:                                                          \
    virtual varType get##funName(void) const { return varName; } \
                                                                 \
public:                                                          \
    virtual void set##funName(varType var) { varName = var; }

// 对外可以获取,不可以设置
#define STL_SYNTHESIZE_ONLY_GET(varType, varName, funName)       \
private:                                                         \
    varType varName;                                             \
                                                                 \
public:                                                          \
    virtual varType get##funName(void) const { return varName; } \
                                                                 \
private:                                                         \
    virtual void set##funName(varType var) { varName = var; }

// 对外可以获取和设置,对派生类可见
#define STL_SYNTHESIZE_PROTECTED(varType, varName, funName)      \
protected:                                                       \
    varType varName;                                             \
                                                                 \
public:                                                          \
    virtual varType get##funName(void) const { return varName; } \
                                                                 \
public:                                                          \
    virtual void set##funName(varType var) { varName = var; }

// 对外可以获取,不可以设置,对派生类可见
#define STL_SYNTHESIZE_PROTECTED_ONLY_GET(varType, varName, funName) \
protected:                                                           \
    varType varName;                                                 \
                                                                     \
public:                                                              \
    virtual varType get##funName(void) const { return varName; }     \
                                                                     \
protected:                                                           \
    virtual void set##funName(varType var) { varName = var; }

// 对外可见
#define STL_SYNTHESIZE_PUBLIC(varType, varName, funName)         \
public:                                                          \
    varType varName;                                             \
                                                                 \
public:                                                          \
    virtual varType get##funName(void) const { return varName; } \
                                                                 \
public:                                                          \
    virtual void set##funName(varType var) { varName = var; }

// 静态 对外可以获取和设置
#define STL_STATIC_SYNTHESIZE(className, varType, varName, funName)  \
private:                                                             \
    static varType varName;                                          \
                                                                     \
public:                                                              \
    static varType get##funName(void) { return className::varName; } \
                                                                     \
public:                                                              \
    static void set##funName(varType var) { className::varName = var; }

// 静态 对外可以获取,不可以设置
#define STL_STATIC_SYNTHESIZE_ONLY_GET(className, varType, varName, funName) \
private:                                                                     \
    static varType varName;                                                  \
                                                                             \
public:                                                                      \
    static varType get##funName(void) { return className::varName; }         \
                                                                             \
private:                                                                     \
    static void set##funName(varType var) { className::varName = var; }

// 静态 对外可以获取,不可以设置,对派生类可见
#define STL_STATIC_SYNTHESIZE_PROTECTED(className, varType, varName, funName) \
protected:                                                                    \
    static varType varName;                                                   \
                                                                              \
public:                                                                       \
    static varType get##funName(void) { return className::varName; }          \
                                                                              \
protected:                                                                    \
    static void set##funName(varType var) { className::varName = var; }

// 静态 对外可见
#define STL_STATIC_SYNTHESIZE_PUBLIC(varType, varName, funName)         \
public:                                                                 \
    static varType varName;                                             \
                                                                        \
public:                                                                 \
    static virtual varType get##funName(void) const { return varName; } \
                                                                        \
public:                                                                 \
    static virtual void set##funName(varType var) { varName = var; }

// volatile 用于标记位,对外可控
#define STL_VOLATILE_SYNTHESIZE_PROTECTED(varType, varName, funName) \
protected:                                                           \
    volatile varType varName;                                        \
                                                                     \
public:                                                              \
    virtual varType get##funName(void) const { return varName; }     \
                                                                     \
public:                                                              \
    virtual void set##funName(varType var) { varName = var; }

// volatile 用于标记位,对外不可控
#define STL_VOLATILE_SYNTHESIZE_PROTECTED_ONLY_GET(varType, varName, funName) \
protected:                                                                    \
    volatile varType varName;                                                 \
                                                                              \
public:                                                                       \
    virtual varType get##funName(void) const { return varName; }              \
                                                                              \
protected:                                                                    \
    virtual void set##funName(varType var) { varName = var; }

#define STL_STATUS_CALLBACK(statusEnum)                                               \
public:                                                                               \
    typedef std::function<void(statusEnum)> StatusCallback;                           \
    void setStatusCallback(StatusCallback callback) { m_statusCallback = callback; }; \
    statusEnum getStatus(void) { return m_status; };                                  \
                                                                                      \
protected:                                                                            \
    statusEnum m_status;                                                              \
    StatusCallback m_statusCallback;                                                  \
    void setStatus(statusEnum status)                                                 \
    {                                                                                 \
        m_status = status;                                                            \
        if (m_statusCallback)                                                         \
        {                                                                             \
            m_statusCallback(m_status);                                               \
        }                                                                             \
    };
